<template>
  <el-table :data="invoiceRequestList">
    <el-table-column
      align="center"
      prop="trade_no"
      label="订单流水号"
    ></el-table-column>
    <el-table-column
      align="center"
      prop="buyerLogonId"
      label="付款帐号"
    ></el-table-column>
    <el-table-column
      align="center"
      prop="realName"
      label="申请人"
    ></el-table-column>
    <el-table-column
      align="center"
      prop="enterName"
      label="报销单位名称"
    ></el-table-column>
    <el-table-column
      align="center"
      prop="enterNumber"
      label="单位社会信用代码"
    ></el-table-column>
    <el-table-column
      align="center"
      prop="totalAmount"
      label="金额"
    ></el-table-column>
    <el-table-column
      align="center"
      prop="sendPayDate"
      label="申请时间"
    ></el-table-column>
    <el-table-column fixed="right" align="center" label="操作">
      <template #default="scope">
        <el-button
          size="small"
          type="primary"
          @click="submitInvoice(scope.row)"
        >
          立即开票
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
import { selectInvoiceRequest, submitRequest } from '@/api/charge'
import { onMounted, ref } from 'vue'
import { ElMessage } from 'element-plus'
var invoiceRequestList = ref([])
var result = ref(false)
onMounted(async () => {
  invoiceRequestList.value = (await selectInvoiceRequest()).data
})
async function submitInvoice(row) {
  ElMessage.success('开票申请已提交，后续结果将通过邮件或短信方式通知')
  result.value = (await submitRequest(row)).data
  if (result.value) {
    ElMessage({
      type: 'success',
      message: '开票成功',
    })
    location.reload()
  } else {
    ElMessage({
      type: 'error',
      message: '开票失败',
      duration: 500,
      onClose: () => {
        location.reload()
      },
    })
  }
}
</script>
